<?php
require_once 'renderer_relation.php';

class renderer_relation_belongs_to extends renderer_relation
{
    
    public function searchRender($fObject)
    {
        $coll = $fObject->getOptions();
        $this->lead->viewer->coll = $coll;
        
        DatatypeRenderer::getInstance()->stackOwner($fObject->getName());
           
        $this->lead->viewer->fObject = $fObject;
		$this->lead->viewer->fRenderer = $this;
        
		/*
        $items = array();
        foreach($coll as $key => $item)
        {
            $items[$item->edoid] = $fObject->resolveTags($item, $fObject->getConfig('display'));
        }
        */
		
        $this->lead->viewer->items = $coll;

        
               
        $tpl = $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/search_list_all.tpl");       
        DatatypeRenderer::getInstance()->unStackOwner();
        return $tpl;

    }
    
    
    public function viewRender($fObject)
    {
        if($fObject->getValue())        
            return $fObject->resolveTags($fObject->getValue(), $fObject->getConfig('display'));
    }
  
    
    public function editRender($fObject)
    {
               
        $this->lead->viewer->fObject = $fObject;
        
        $options = $fObject->getOptions();
         
        $selected = null;       
        if($fObject->getValue())
        {
            $selected = $fObject->getOwner()->getField($fObject->getForeignKey());
            $inlineObj = $fObject->getValue();
            $this->lead->viewer->inlineObj = $inlineObj;
            
            
            
            
            $dier = true;
            
        }
        
        $this->lead->viewer->selected = $selected;
        $this->lead->viewer->options = $options;
       
        if($fObject->getConfig('render_as') == 'link')
        {
            if($fObject->getValue())
            {
                $displayValue = $fObject->resolveTags($fObject->getValue(), $fObject->getConfig('display'));
                $this->lead->viewer->displayValue = $displayValue;    
                return $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/link.tpl");                   
            }
           
            
        }
        else 
        {
            
            return $this->lead->viewer->fetch("{$this->path}/{$this->folderName}/edit_dropdown.tpl");                   
        }
        
        
            
                        
    }
    
    
    
    
}